package com.ismartv.sale.control;

import com.ismartv.sale.util.ExportExcel;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;

public class RegionSaleReport extends HttpServlet {

	private HSSFWorkbook regionReport;
	private String startDate;
	private String endDate;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// resp.setContentType("text/json;charset=utf-8");
		regionReport = new HSSFWorkbook();
		resp.setContentType("application/msexcel;charset=UTF-8");
		resp.addHeader("Content-Disposition", "attachment;filename=\""
				+ new String("数据需求" + new Date().toString() + ".xlsx") + "\"");
		OutputStream out = resp.getOutputStream();
		HSSFSheet sheet = regionReport.createSheet("各地线下销售产品的激活数量");
		ExportExcel exceldata = new ExportExcel(regionReport, sheet);
		exceldata.createRegionHead();
		regionReport.write(out);
		resp.flushBuffer();
		out.flush();
		out.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	}

	private void dispatchAction(HttpServletResponse resp, String action)
			throws ServletException, IOException {
		resp.sendRedirect(action);
	}

}
